package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Requirement;
import cn.wolfcode.crm.mapper.RequirementMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.RequireQueryObject;
import cn.wolfcode.crm.service.IRequirementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RequirementServiceImpl implements IRequirementService {

    @Autowired
    private RequirementMapper requirementMapper;

    public void insert(Requirement entity) {
        entity.setInputTime(new Date());
        entity.setInputUser(new Employee());//设置当前登录用户为申请人(登录页面写好再改)
        requirementMapper.insert(entity);
    }

    public void delete(Long id) {
        requirementMapper.deleteByPrimaryKey(id);
    }

    public void update(Requirement entity) {
        requirementMapper.updateByPrimaryKey(entity);
    }

    public Requirement get(Long id) {
        return  requirementMapper.selectByPrimaryKey(id);
    }

    public List<Requirement> list() {
        return  requirementMapper.selectAll();
    }

    public PageResult query(RequireQueryObject qo) {
        int total =  requirementMapper.queryForCount(qo);
        List<Requirement> rows =  requirementMapper.queryForList(qo);
        return new PageResult(total,rows);
    }
}
